#include <xpp/net/UdpSocket.h>
#include <xpp/net/UdpAddress.h>
#include <xp/bas/stdio.h>

using namespace xpp;
using namespace xpp::net;

extern "C" { int xp_main (); }

int xp_main ()
{
	if (Socket::startup() == -1) {
		xp_printf (XP_TEXT("cannot initialize the socket subsystem\n"));
		return -1;
	}

	UdpSocket sock;
	if (sock.open (UdpAddress()) == -1) {
		xp_printf (XP_TEXT("cannot open a socket - %d\n"), sock.errorCode());
		return -1;
	}

	InetAddress addr;
	EtherAddress ether;
	xp_printf (XP_TEXT("%d\n"), sock.getIfceIndex(XP_TEXT("eth0")));
	sock.getIfceInetAddress (XP_TEXT("eth0"), &addr);
	xp_printf (XP_TEXT("%s\n"), (const xp_char_t*)addr.numericHost());
	sock.getIfceNetmask (XP_TEXT("eth0"), &addr);
	xp_printf (XP_TEXT("%s\n"), (const xp_char_t*)addr.numericHost());
	sock.getIfceBroadcast (XP_TEXT("eth0"), &addr);
	xp_printf (XP_TEXT("%s\n"), (const xp_char_t*)addr.numericHost());
	sock.getIfceEtherAddress (XP_TEXT("eth0"),&ether);
	xp_printf (XP_TEXT("%s\n"), (const xp_char_t*)ether.toString());

	xp_printf (XP_TEXT("%d\n"), sock.getIfceIndex(XP_TEXT("eth1:1")));
	sock.getIfceInetAddress (XP_TEXT("eth1:1"), &addr);
	xp_printf (XP_TEXT("%s\n"), (const xp_char_t*)addr.numericHost());
	sock.getIfceNetmask (XP_TEXT("eth1:1"), &addr);
	xp_printf (XP_TEXT("%s\n"), (const xp_char_t*)addr.numericHost());
	sock.getIfceBroadcast (XP_TEXT("eth1:1"), &addr);
	xp_printf (XP_TEXT("%s\n"), (const xp_char_t*)addr.numericHost());
	sock.getIfceEtherAddress (XP_TEXT("eth1:1"), &ether);
	xp_printf (XP_TEXT("%s\n"), (const xp_char_t*)ether.toString());
	
	Socket::cleanup ();
	return 0;
}
